package com.wdl.modules.myhouse.utils.util;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.TypeReference;
import com.wdl.modules.myhouse.entity.FileDescEntity;
import com.wdl.modules.myhouse.entity.FileEntity;
import org.springframework.scheduling.concurrent.DefaultManagedAwareThreadFactory;
import springfox.documentation.spring.web.json.Json;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.*;

public class IOutil {

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                4, // 最大核心线程数量
                16, // 最大线程数量 = 核心线程数量 + 临时线程数量
                1000, // 临时线程的最大空闲时间，超过这个时间将会被销毁
                TimeUnit.MILLISECONDS, // 时间单位
                new LinkedBlockingDeque<>(), // 任务队列的容器
                new DefaultManagedAwareThreadFactory() // 线程创建工厂类
        );


        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
            getCatData("one:");
        }, pool);

        CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> {
            getCatData("two");
        }, pool);

        CompletableFuture.allOf(future,future2);
        future.get();
        future2.get();

        System.out.println("helloworld");
    }

    public static void getCatData(String name){
        for (int i = 0; i < 1000; i++) {
            System.out.println(name+i);
        }
    }







    public static String readFromFile(String filePath) throws IOException {

        FileReader reader1 = new FileReader(filePath);
        BufferedReader reader = new BufferedReader(reader1);
        String s = null;
        StringBuilder builder = new StringBuilder();
        do {
            s = reader.readLine();
            builder.append(s);
        } while (s != null);
        return builder.toString();


    }

}
